package internal

import (
	"context"
	"time"

	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/os/gtime"

	"github.com/beherochuling/beesoft_api/app/helper/helper/internal/sonyflake"
)

func CreateSonyID(startTime ...time.Time) uint64 {
	var id uint64 = 0
	g.TryCatch(context.Background(), func(ctx context.Context) {
		sonySetting := sonyflake.Settings{}
		if len(startTime) > 0 {
			sonySetting.StartTime = startTime[0]
		}
		sonyFlake := sonyflake.NewSonyflake(sonySetting)
		sonyId, _ := sonyFlake.NextID()
		id = sonyId
	}, func(ctx context.Context, exception error) {
		id = uint64(gtime.Now().TimestampMicro())
	})
	return id
}
